package com.mxpio.erp.technology.controller;

import com.mxpio.erp.common.technology.entity.ProdTecRoutProcTechDrawingSignIn;
import com.mxpio.erp.common.technology.service.ProdTecRoutProcTechDrawingSignInService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "ProdTecRoutProcTechDrawingSignInController", description = "产品工艺路线明细(工序)工艺图纸签入申请")
@RestController
@RequestMapping("/erp/tech/prodrout/proc/drawingfile/signin/")
public class ProdTecRoutProcTechDrawingSignInController {

	@Autowired
	private ProdTecRoutProcTechDrawingSignInService service;

	@GetMapping("list")
	@Operation(summary = "产品工艺路线明细(工序)工艺图纸签入申请列表", description = "获取产品工艺路线明细(工序)工艺图纸签入申请列表", method = "GET")
	public Result<List<ProdTecRoutProcTechDrawingSignIn>> list(Criteria criteria)  {
		List<ProdTecRoutProcTechDrawingSignIn> itemDesignFileSignIns = service.list(ProdTecRoutProcTechDrawingSignIn.class, criteria);
		return Result.OK(itemDesignFileSignIns);
	}

	@GetMapping("list/{code}")
	@Operation(summary = "根据code获取工艺图纸签入申请", description = "根据code获取工艺图纸签入申请", method = "GET")
	public Result<ProdTecRoutProcTechDrawingSignIn> getById(@PathVariable(name = "code", required = true) String code) {
		ProdTecRoutProcTechDrawingSignIn signIn = service.getByIdWith( code);
		return Result.OK(signIn);
	}
	@GetMapping("page")
	@Operation(summary = "产品工艺路线明细(工序)工艺图纸签入申请列表", description = "获取产品工艺路线明细(工序)工艺图纸签入申请列表", method = "GET")
	public Result<Page<ProdTecRoutProcTechDrawingSignIn>> page(Criteria criteria, Integer pageSize, Integer pageNo) {
		Pageable page = PageRequest.of(pageNo-1, pageSize);
		Page<ProdTecRoutProcTechDrawingSignIn> itemDesignFileSignIns = service.listPage(ProdTecRoutProcTechDrawingSignIn.class, page, criteria);
		return Result.OK(itemDesignFileSignIns);
	}
	@PutMapping("edit")
	@Operation(summary = "编辑 产品工艺路线明细(工序)工艺图纸签入", description = "编辑产品工艺路线明细(工序)工艺图纸签入(工作流回调 ，回写审核状态及流程实例ID)", method = "PUT")
	public Result<ProdTecRoutProcTechDrawingSignIn> edit(@RequestBody ProdTecRoutProcTechDrawingSignIn signIn) {
		service.update(signIn);
		return Result.OK(signIn);
	}

	@GetMapping("audit_pass/{code}/{result}")
	@Operation(summary = "产品工艺路线明细(工序)工艺图纸签入申请-审核结果回调", description = "产品工艺路线明细(工序)工艺图纸签入申请-审核结果回调", method = "GET")
	public Result<ProdTecRoutProcTechDrawingSignIn> auditPass(@PathVariable(name = "code", required = true) String code ,@PathVariable(name = "result", required = true) String result ) {
		return service.auditPass(code,result);
	}
}
